package com.hmjk.health.background;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.HashMap;


public class HttpConf {
	private static final String Domain = "app.hmjk.hmyd.com";
	//private static final String Domain = "192.168.20.166"; //test server
	//private static final String Domain = "192.168.20.237"; //yynie test server swbuild098
	public static final int port = 80;
	private static final String SSLDomain = "app.hmjk.hmyd.com";
	//private static final String SSLDomain = "192.168.20.166";//test sever
	//private static final String SSLDomain = "192.168.20.237"; //yynie test sever swbuild098
	public static final int sslport = 443;
	public static final String HEADER_CONTENT_TYPE = "Content-Type";
	public static final String HEADER_CONTENT_TYPE_JSON = "application/json;charset=UTF-8";
	public static final String HEADER_CONNECTION = "Connection";
	
	public static HashMap<String, String> parse(String uri){
		
		if(uri == null || uri.trim().isEmpty())
			return null;
		
		int pos = uri.indexOf("?");
		HashMap<String, String> map = new HashMap<String, String>();
		
		if(pos > 0){
			String domain = uri.substring(0, pos);
			map.put("domain", domain);
			String next = uri.substring(pos + 1);
			
			String key,value;
			while(next.length()>0){
				pos = next.indexOf("=");
				if(pos > 0){
					key = next.substring(0,pos);
					next = next.substring(pos + 1);
					pos = next.indexOf("&");
					if(pos > 0){
						value = next.substring(0,pos);
						next = next.substring(pos + 1);
					}else{
						value = next;
						next = "";
					}
					if(key!=null && value!=null){
						map.put(key, value);
					}
				}
			}
		}else{
			map.put("domain", uri);
		}
		
		return map;
	}
	
	
	public static String getApkUri(){
		return "http://a.app.qq.com/o/simple.jsp?pkgname=com.hmjk.health";
	}
	
	public static boolean mine(String uri){
		return uri.toLowerCase().startsWith(getHomePageUri());
	}
	
	public static String getHomePageUri(){
		return "http://app.hmjk.hmyd.com";
	}
	
	public static String getFamilyInvitationUri(String fid, String fname){
		
		try {
			String gfname = URLEncoder.encode(fname,"UTF-8");
			String u = getHomePageUri() + "?action=invite2fa&fid="+fid+"&fname="+gfname;
			return u;
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}
	
	public static String getDeviceManageUri(String did){
		String u = getHomePageUri() + "?action=adddev&did="+did;
		return u;
	}

	public static String getDeviceInterestUri(String tid, String dname){
		
		try {
			String guname = URLEncoder.encode(dname,"UTF-8");
			String u = getHomePageUri() + "?action=interestdev&tid="+tid+"&dname="+guname;
			return u;
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}
	
	public static String ValidateAccountUri(){
		return "https://" + SSLDomain + ":" + sslport + "/user/uservalid";
	}
	
	/*public static String ValidatePhoneUri(){
		return "Https://" + SSLDomain + ":" + sslport + "/user/mobilevalid";
	}*/
	
	public static String IdentifyCodeUri(){
		return "https://" + SSLDomain + ":" + sslport + "/user/getvalidcode";
	}
	
	public static String signUpUri(){
		return "https://" + SSLDomain + ":" + sslport + "/user/userregistered";
	}
	
	public static String signInUri(){
		return "https://" + SSLDomain + ":" + sslport + "/login/password";
	}
	
	public static String changePasswordUri(){
		return "https://" + SSLDomain + ":" + sslport + "/other/changepassword";
	}
	
	public static String retrievePasswordUri(){
		return "https://" + SSLDomain + ":" + sslport + "/other/getpassword";
	}
	
	public static String getUserDataUri(){
		return "https://" + SSLDomain + ":" + sslport + "/query/userdetail";
	}
	
	public static String getUserFaceCheckUri(){
		return "https://" + SSLDomain + ":" + sslport + "/user/validtimestamp";
	}
	
	public static String getFamilyDetailUri(){
		return "https://" + SSLDomain + ":" + sslport + "/query/familydetail";
	}
	
	public static String getFamilyListUri(){
		return "https://" + SSLDomain + ":" + sslport + "/query/familylist";
	}
	
	public static String getDeviceListUri(){
		return "https://" + SSLDomain + ":" + sslport + "/query/terminallist";
	}
	
	public static String getDeviceSubListUri(){
		return "https://" + SSLDomain + ":" + sslport + "/other/querysublist";
	}
	
	public static String getDeviceSubInfoUri(){
		return "https://" + SSLDomain + ":" + sslport + "/other/querysub";
	}
	
	public static String getDeviceFaceCheckUri(){
		return "https://" + SSLDomain + ":" + sslport + "/terminal/validtimestamp";
	}
	
	public static String getFamilyMembersUri(){
		return "https://" + SSLDomain + ":" + sslport + "/query/memberlist";
	}
	
	public static String getUserDataUpateUri(){
		return "https://" + SSLDomain + ":" + sslport + "/user/updateuserdetail";
	}
	
	public static String getBuildFamilyUri(){
		return "https://" + SSLDomain + ":" + sslport + "/family/createfamily";
	}
	
	public static String getApplyJoinFamilyUri(){
		return "https://" + SSLDomain + ":" + sslport + "/family/bindmembers";
	}
	
	public static String getUpdateFamilyDetailUri(){
		return "https://" + SSLDomain + ":" + sslport + "/family/updatedetail";
	}
	
	public static String getFamilySetAdminUri(){
		return "https://" + SSLDomain + ":" + sslport + "/family/setadmin";
	}
	
	public static String getFamilyAbortByAdminUri(){
		return "https://" + SSLDomain + ":" + sslport + "/family/abortbindadmin";
	}
	
	public static String getFamilyAbortByMemberUri(){
		return "https://" + SSLDomain + ":" + sslport + "/family/abortbindmember";
	}

	public static String getDeviceSettinsUri(){
		return "https://" + SSLDomain + ":" + sslport + "/query/terminalinfo";
	}
	
	public static String getDevicePowerUri(){
		return "https://" + SSLDomain + ":" + sslport + "/other/querypower";
	}
	
	public static String getQueryLocationPageUri(){
		return "https://" + SSLDomain + ":" + sslport + "/other/queryperiod";
	}
	
	public static String getQueryLocationCountUri(){
		return "https://" + SSLDomain + ":" + sslport + "/other/querylatest";
	}
	
	public static String getQueryLocationNewestUri(){
		return "https://" + SSLDomain + ":" + sslport + "/other/querynewlocations";
	}
	
	public static String getAddNewDeviceUri(){
		return "https://" + SSLDomain + ":" + sslport + "/terminal/bindadmin";
	}
	
	public static String getDeviceAbortAdminUri(){
		return "https://" + SSLDomain + ":" + sslport + "/terminal/abortbindadmin";
	}
	
	public static String getDeviceApplyAdminUri(){
		return getAddNewDeviceUri();
	}
	
	public static String getDeviceAbortInterestUri(){
		return "https://" + SSLDomain + ":" + sslport + "/terminal/abortbindinterest";
	}
	
	public static String getUpdateDeviceMobileNumberUri(){
		return "https://" + SSLDomain + ":" + sslport + "/terminal/updatesim";
	}
	
	public static String getQueryDeviceLocaParamUri(){
		return "https://" + SSLDomain + ":" + sslport + "/query/syncinfo";
	}
	
	public static String getActivateDeviceUri(){
		return "https://" + SSLDomain + ":" + sslport + "/terminal/activated";
	}
	
	public static String getSetDeviceLocaParamUri(){
		return "https://" + SSLDomain + ":" + sslport + "/terminal/updatedetail";
	}
	
	public static String getUpdateDeviceNameUri(){
		return "https://" + SSLDomain + ":" + sslport + "/terminal/updatename";
	}
	
	public static String getApplyInterestDeviceUri(){
		return "https://" + SSLDomain + ":" + sslport + "/terminal/bindinterest";
	}
	
	public static String getQueryToDoListUri(){
		return "https://" + SSLDomain + ":" + sslport + "/other/getmatter";
	}
	
	public static String getDealToDoUri(){
		return "https://" + SSLDomain + ":" + sslport + "/other/postmatter";
	}
	
	public static String getDownloadADUri(){
		return "https://" + SSLDomain + ":" + sslport + "/other/getad";
	}

	public static String setCareRminderUri(){
		return "https://" + SSLDomain + ":" + sslport + "/other/setremindcare";
	}	
	
	public static String getCareRminderUri(){
		return "https://" + SSLDomain + ":" + sslport + "/other/queryremindcare";
	}
	
	public static String setMeasureRminderUri(){
		return "https://" + SSLDomain + ":" + sslport + "/other/setremindmeasure";
	}	
	
	public static String getMeasureRminderUri(){
		return "https://" + SSLDomain + ":" + sslport + "/other/queryremindmeasure";
	}
	
	public static String setDrugRminderUri(){
		return "https://" + SSLDomain + ":" + sslport + "/other/setreminddrug";
	}	
	
	public static String getDrugRminderUri(){
		return "https://" + SSLDomain + ":" + sslport + "/other/queryreminddrug";
	}		
	
	public static String setGlycoseSetUri(){
		return "https://" + SSLDomain + ":" + sslport + "/bg/updateparam";
	}	
	
	public static String getGlycoseSetUri(){
		return "https://" + SSLDomain + ":" + sslport + "/bg/queryparam";
	}
	
	public static String getGlycoseDataUri(){
		return "https://" + SSLDomain + ":" + sslport + "/bg/querylatest";
	}	
	
	public static String getGlycoseDatapageUri(){
		return "https://" + SSLDomain + ":" + sslport + "/bg/queryperiod";
	}
	
	public static String getBpDatapageUri(){
		return "https://" + SSLDomain + ":" + sslport + "/bp/queryperiod";
	}
	
	//http uri start from here
	public static String getUpdateUserFaceUri(){
		return "http://" + Domain + ":" + port + "/user/updateface";
	}
	
	public static String getUpdateDevFaceUri(){
		return "http://" + Domain + ":" + port + "/terminal/updateface";
	}
	
	public static String getDownloadUserFaceUri(String uid, String type){
		return "http://" + Domain + ":" + port + "/user/face/" + uid + "/" + type;
	}
	
	public static String getDownloadDeviceFaceUri(String tid, String type){
		return "http://" + Domain + ":" + port + "/terminal/face/" + tid + "/" + type;
	}
	
	public static String getAgreementUri(){
		return "http://" + Domain + ":" + port + "/other/agreement.html";
	}	
	
	public static String getAboutUsUri(){
		return "http://" + Domain + ":" + port + "/other/about.html";
	}	
	
	public static String getUserManualUri(){
		return "http://" + Domain + ":" + port + "/other/manual.html";
	}
}
